//===============================================================================
// Microsoft patterns & practices Enterprise Library Contribution
// Policy Injection Application Block
//===============================================================================

using Microsoft.Practices.EnterpriseLibrary.Common.Configuration;
using Microsoft.Practices.EnterpriseLibrary.PolicyInjection.Configuration;
using Microsoft.Practices.Unity;
using Microsoft.Practices.Unity.InterceptionExtension;

namespace EntLibContrib.PolicyInjection.CallHandlers.Configuration
{
	/// <summary>
	/// Synchronized Call Handler Data
	/// </summary>
	public class SynchronizedCallHandlerData : CallHandlerData
	{
		#region Construction
		/// <summary>
		/// Construct a new <see cref="SynchronizedCallHandlerData"/>.
		/// </summary>
		public SynchronizedCallHandlerData()
		{
		}

		/// <summary>
		/// Construct a new <see cref="SynchronizedCallHandlerData"/>.
		/// </summary>
		/// <param name="handlerName">Name of the handler.</param>
		public SynchronizedCallHandlerData(string handlerName)
			: base(handlerName, typeof(SynchronizedCallHandler))
		{
		}

		/// <summary>
		/// Construct a new <see cref="SynchronizedCallHandlerData"/>.
		/// </summary>
		/// <param name="handlerName">Name of the handler.</param>
		/// <param name="handlerOrder">The handler order.</param>
		public SynchronizedCallHandlerData(string handlerName, int handlerOrder)
			: base(handlerName, typeof(SynchronizedCallHandler))
		{
			Order = handlerOrder;
		}
		#endregion

		#region Public Methods
		/// <summary>
		/// Adds the call handler represented by this configuration object to <paramref name="policy"/>.
		/// </summary>
		/// <param name="policy">The policy to which the rule must be added.</param>
		/// <param name="configurationSource">The configuration source from which additional information
		/// can be retrieved, if necessary.</param>
		public override void ConfigurePolicy(PolicyDefinition policy, IConfigurationSource configurationSource)
		{
			policy.AddCallHandler<SynchronizedCallHandler>(
					new ContainerControlledLifetimeManager(),
					new InjectionConstructor(
							new InjectionParameter<int>(this.Order)));
		}
		#endregion
	}
}
